package org.jeecg.modules.demo.weixin.smtyuyueuser.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.demo.mall.api.MallHelloApi;
import org.jeecg.modules.demo.mall.entity.YxUser;
import org.jeecg.modules.demo.weixin.dto.PayDto;
import org.jeecg.modules.demo.weixin.entity.SmtYuyueUser;
import org.jeecg.modules.demo.weixin.smtyuyueuser.mapper.SmtYuyueUserMapper;
import org.jeecg.modules.demo.weixin.smtyuyueuser.service.ISmtYuyueUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 预约场次人员表
 * @Author: jeecg-boot
 * @Date:   2023-10-27
 * @Version: V1.0
 */
@Service
public class SmtYuyueUserServiceImpl extends ServiceImpl<SmtYuyueUserMapper, SmtYuyueUser> implements ISmtYuyueUserService {

    @Autowired
    private MallHelloApi mallHelloApi;

    @Override
    public void saveUser(PayDto payDto) {
        for (int i = 0; i < payDto.getCount(); i++) {
            SmtYuyueUser yuyueUser = new SmtYuyueUser();
            if (payDto.getUid()!=null){
                yuyueUser.setUserId(payDto.getUid());
                YxUser yxUser = mallHelloApi.queryUser(payDto.getUid());
                if (yxUser!=null){
                    if (StringUtils.isNotBlank(yxUser.getAvatar())){
                        yuyueUser.setAvatar(yxUser.getAvatar());
                        yuyueUser.setNickname(yxUser.getNickname());
                    }else {
                        yuyueUser.setAvatar("https://cdn.ybh.gengduoke.com/qita234.jpg");
                    }

                }
            }else {
                yuyueUser.setAvatar("https://cdn.ybh.gengduoke.com/qita234.jpg");
            }
            yuyueUser.setLinkPayOrderNo(payDto.getOrderCouponNo());
            yuyueUser.setId(payDto.getYuYueId());
            yuyueUser.setUserType(4);
            yuyueUser.setOrd(payDto.getOrd());
            yuyueUser.setQrCode(payDto.getQrCode());
            this.save(yuyueUser);
        }
    }
}
